//
//  MainTabBar.swift
//  SinaWeiBo
//
//  Created by moon on 15/10/5.
//  Copyright © 2015年 moon. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

  
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        var index: CGFloat = 0
        
        let W=UIScreen.mainScreen().bounds.width/5
        
        let H=self.bounds.height
        
        let frame=CGRectMake(0, 0, W, H)
        
        for view in subviews{
        
            if view is UIControl && !(view is UIButton){
            
                
            view.frame=CGRectOffset(frame, index*W, 0)
                
                
                
//                if(index == 1){
//                
//                index++
//                
//                }
//            
//                index++
              
                index += (index == 1 ? 2 : 1)
                
                
            }
       
        }
        
      centerButton.frame=CGRectOffset(frame, 2*W, 0)
        
    }
    
  //懒加载一个按钮
   
    lazy var centerButton: UIButton = {
             
    let button=UIButton(type: UIButtonType.Custom)
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
       self.addSubview(button)
        
    return button
        
    
    
    }()

}
